﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using XiAnAirport.BUS;
using XiAnAirport.DAL;
using XiAnAirport.Models;

namespace XiAnAirport.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PanoramicController : ControllerBase
    {
        public PanoramicController(
        )
        {
        }

        [HttpPost]
        [HttpGet]
        [Route("QueryDeviceBasicInfo")]
        public PanoramicDeviceReturnInfo QueryDeviceBasicInfo(PanoramicInfo panoramicInfo)
        {
            PanoramicDeviceReturnInfo panoramicDeviceReturnInfo = new PanoramicDeviceReturnInfo();
            List<PanoramicElevatorData> panoramicElevatorData = new List<PanoramicElevatorData>();
            try
            {
                panoramicDeviceReturnInfo.code = 200;
                ElevatorAreaBUS elevatorAreaBUS = new ElevatorAreaBUS();
                ElevatorAreaDAL elevatorAreaDAL = new ElevatorAreaDAL();
                if (!string.IsNullOrEmpty(panoramicInfo.assetCode))
                {
                    panoramicElevatorData = elevatorAreaBUS.QueryPanoramicElevator(panoramicInfo.assetCode);
                    panoramicDeviceReturnInfo.data = panoramicElevatorData;
                    panoramicDeviceReturnInfo.total = elevatorAreaDAL.QueryPanoramicElevatorConut(panoramicInfo.assetCode);
                }
                else
                {
                    int Recordhead = 0;
                    int Recordtail = 0;
                    if (panoramicInfo.page > 0 && panoramicInfo.size > 0)
                    {
                        Recordhead = (panoramicInfo.page - 1) * panoramicInfo.size;
                        Recordtail = panoramicInfo.size;
                    }
                    panoramicElevatorData = elevatorAreaBUS.QueryPanoramicElevator(Recordhead, Recordtail);
                    panoramicDeviceReturnInfo.data = panoramicElevatorData;
                    panoramicDeviceReturnInfo.total = elevatorAreaDAL.QueryPanoramicElevatorConut();
                }
               
            }
            catch (Exception e)
            {
            }
            return panoramicDeviceReturnInfo;
        }

        [HttpPost]
        [HttpGet]
        [Route("QueryDeviceMetricsInfo")]
        public PanoramicMetricsReturnInfo QueryDeviceMetricsInfo(PanoramicInfo panoramicInfo)
        {
            PanoramicMetricsReturnInfo panoramicReturnInfo = new PanoramicMetricsReturnInfo();
            List<PanoramicMetrics> list = new List<PanoramicMetrics>();
            try
            {
                ElevatorStateBUS elevatorStateBUS = new ElevatorStateBUS();
                list = elevatorStateBUS.GetPanoramicData();
                panoramicReturnInfo.total = 1;
                panoramicReturnInfo.data = list;
            }
            catch (Exception e)
            {
                panoramicReturnInfo.total = 1;
                panoramicReturnInfo.data = list;
            }
            return panoramicReturnInfo;
        }

        [HttpPost]
        [HttpGet]
        [Route("QueryDeviceInfoByCode")]
        public PanoramicDeviceReturnInfo QueryDeviceInfoByCode(PanoramicDeviceInfo panoramicInfo)
        {
            PanoramicDeviceReturnInfo panoramicDeviceReturnInfo = new PanoramicDeviceReturnInfo();
            List<PanoramicElevatorData> panoramicElevatorData = new List<PanoramicElevatorData>();
            try
            {
                panoramicDeviceReturnInfo.code = 200;
                ElevatorAreaBUS elevatorAreaBUS = new ElevatorAreaBUS();
                ElevatorAreaDAL elevatorAreaDAL = new ElevatorAreaDAL();
               
                panoramicElevatorData = elevatorAreaBUS.QueryPanoramicElevator(panoramicInfo.assetCode);
                panoramicDeviceReturnInfo.data = panoramicElevatorData;
                panoramicDeviceReturnInfo.total = elevatorAreaDAL.QueryPanoramicElevatorConut(panoramicInfo.assetCode);
            }
            catch (Exception e)
            {
            }
            return panoramicDeviceReturnInfo;
        }
    }
}
